package cn.edu.neusoft.zengweidong707.neufood.fragment;


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * A simple {@link Fragment} subclass.
 */
public abstract class BaseFragment extends Fragment {
    protected int layout_file = 0;
    private SharedPreferences sp;
    View view = null;

    abstract void initView();
    abstract void initEvent();
    abstract void initData();

    public int getLayout_file() {
        return layout_file;
    }

    public void setLayout_file(int layout_file) {
        this.layout_file = layout_file;
    }

    public BaseFragment() {
        // Required empty public constructor

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(getLayout_file(), container, false);
        initView();
        initEvent();
        initData();
        return view;
    }

    protected String getUsername() {
        sp = getActivity().getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        return sp.getString("username", "");
    }

    protected String getUserid() {
        sp = getActivity().getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        return sp.getString("userid", "");
    }

}
